package com.naiterui.ehp.bs.b2c.order.controller.inner;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.naiterui.ehp.bp.bo.payment.NotifyBusinessRefundBO;
import com.naiterui.ehp.bp.constants.SwaggerTag;
import com.naiterui.ehp.bp.support.exception.BusinessException;
import com.naiterui.ehp.bp.utils.payment.bo.NotifyBusinessPayBO;
import com.naiterui.ehp.bs.b2c.order.exception.OrderBusinessException;
import com.naiterui.ehp.bs.b2c.order.service.IOrderService;
import com.naiterui.ehp.bs.b2c.order.service.IRefundOrderService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * <pre>
 *     支付服务回调通知
 * </pre>
 *
 * @author 王泽浩
 * @since 1.0.0
 */
@Slf4j
@Api(tags = SwaggerTag.INNER_API + SwaggerTag.ORDER)
@Controller
@ResponseBody
@RequestMapping("b2c/inner/notify")
public class InnerNotifyPayController {

    @Autowired
    private IOrderService orderService;
    @Autowired
    private IRefundOrderService refundOrderService;

    @ApiOperation(value = "支付回调通知")
    @PostMapping(value = "pay")
    public String notifyPay(@RequestBody NotifyBusinessPayBO request) throws OrderBusinessException {
        log.info("支付回调通知数据：{}", request);
        this.orderService.notifyOrderPayStatus(request);
        return "success";
    }

    @PostMapping("refund")
    @ApiOperation(value = "退款成功通知")
    public String notifyRefund(@RequestBody NotifyBusinessRefundBO request) throws BusinessException {
        log.info("退款回调通知数据：{}", request);
        this.refundOrderService.notifyOrderRefundStatus(request);
        return "success";
    }
}
